package com.wanmait.server.controller;

import com.google.common.collect.Maps;
import com.wanmait.common.response.BaseResponse;
import com.wanmait.common.response.StatusCode;
import com.wanmait.model.entity.Staff;
import com.wanmait.server.util.ShiroUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @ClassName UserController
 * @Author 羽
 * @Date 2020/12/11 15:50
 * @Version 1.0
 * 用户/员工的信息管理
 **/
@Controller
@RequestMapping("/sysManagement")
public class UserController extends AbstractController{
    /**
    * TODO
    * @author 羽
    * @date 2020/12/11 15:55
    * 获取当前登陆用户的信息
    **/
    @RequestMapping("info")
    @ResponseBody
    public BaseResponse info(){
        //获取当前登录用户
        BaseResponse response = new BaseResponse(StatusCode.Success);
        Map<String,Object> map = Maps.newHashMap();
        try{
            map.put("staff",getLoginStaffInfo());
        }catch (Exception e){
            return new BaseResponse(StatusCode.Fail);
        }
        response.setData(map);
        return response;
    }

    /**
     * TODO
     * @author 羽
     * @date 2020/12/17 16:06
     * 删除操作时，进行密码的验证
     **/
    @RequestMapping("password")
    @ResponseBody
    public BaseResponse password(@RequestBody String password){
        //获取登陆用户名
        Staff staff = getLoginStaffInfo();

        //将获取的密码安规定加密
        String encryptionPassword = ShiroUtil.sha256(password,staff.getSalt());
        if(staff.getPassword().equals(encryptionPassword)){
            return new BaseResponse<String>(StatusCode.Success);
        }

        return new BaseResponse(StatusCode.PassorderVerification);
    }





















}
